""" String helper functions """

# The ordinal value for whitespace is lower than alphanumerics so it functions
# as something of a zero value for strings
DEFAULT_FILLER = ' '

def rfill(string, max_length=50, filler=DEFAULT_FILLER):
  """ Returns the string with filler characters to the right
  
  Length of returned string should be max_length
  
  >>> rfill('asdf', 10, '@')
  'asdf@@@@@@'
  >>> rfill('asdf', 3, '@')
  'asd'
  
  """
  fill_count = max_length - len(string)
  if fill_count < 0:
    return string[:max_length]
  else:
    return ''.join([string] + [filler for i in range(fill_count)])

def lfill(string, max_length=50, filler=DEFAULT_FILLER):
  """ Returns the string with filler characters to the left
  
  Length of returned string should be max_length
  
  >>> lfill('asdf', 10, '@')
  '@@@@@@asdf'
  >>> lfill('asdf', 3, '@')
  'asd'
  
  """
  fill_count = max_length - len(string)
  if fill_count < 0:
    return string[:max_length]
  else:
    return ''.join([filler for i in range(fill_count)] + [string])
